package com.mtons.mblog.modules.template.directive;

import com.mtons.mblog.modules.data.QuestVO;
import com.mtons.mblog.modules.service.QuestService;
import com.mtons.mblog.modules.template.DirectiveHandler;
import com.mtons.mblog.modules.template.TemplateDirective;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Component;

/**
 * @program: mblog
 * @description:
 * @author: Mr.Run
 * @create: 2021-04-08 22:26
 **/
@Component
public class UserQuestsDirective extends TemplateDirective {
    @Autowired
    private QuestService questService;

    @Override
    public String getName() {
        return "user_quests";
    }

    @Override
    public void execute(DirectiveHandler handler) throws Exception {
        long userId = handler.getInteger("userId", 0);
        Pageable pageable = wrapPageable(handler);

        Page<QuestVO> result = questService.pagingByAuthorId(pageable, userId);
        handler.put(RESULTS, result).render();
    }
}
